package net.decoder
{
	import away3d.entities.Mesh;
	import away3d.materials.ColorMaterial;
	import away3d.primitives.CubeGeometry;
	
	import controller.FriendRobotController;
	import controller.MainWeaponController;
	import controller.MyRobotController;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.TimerEvent;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	import game.P2pWorld;
	
	import gameObject.Circle;
	import gameObject.Robot;
	import gameObject.SingleBullet;
	import gameObject.WeaponMain;
	import gameObject.resources3D.RobotResource;
	import gameObject.resources3D.WeaponResource;
	
	import net.P2p;
	
	/**
	 * 
	 * 收到netGroup或服务端传来的信息后，统一在这里处理
	 * 为了在NetGroup中NetStream中有一个统一的收取方法，所以所有方法中的参数都为一个数组
	 * 
	 */
	public class DecoderClient extends Sprite
	{
		public function DecoderClient(){}
		
		///////////////////////////////////////////////
		public function addPosData(values:Array):void
		{
			var uid:uint = values[0];
			var posX:Number = values[1]; 
			var posY:Number = values[2]; 
			var dir:Number = values[3]; 
			
			if(uid!=Global.uid)
			{
				var con:FriendRobotController = P2pWorld.robotControllers[uid];
				
				con.PosData=[posX,posY,dir];
				con.gotPosData();
			}else
			{
				var myCon:MyRobotController = P2pWorld.robots[uid].controller as MyRobotController;
				myCon.enableMove = true;
			}
		}
		
		public function tryStopRobot(values:Array):void
		{
			var uid:uint = values[0];
			var posX:Number = values[1]; 
			var posY:Number = values[2]; 
			
			if(uid!=Global.uid)
			{
				var con:FriendRobotController = P2pWorld.robotControllers[uid];
				con.PosData[0]=posX;
				con.PosData[1]=posY;
				con.tryStop();
			}
		}
		
		public function updateBodyDir(values:Array):void
		{
			var uid:int = values[0];
			var robot:Robot = P2pWorld.robots[uid];
			
			var robRes:RobotResource = robot.resource as RobotResource;
			robRes.connector.rotationZ = values[1];
		}
		
		public function updateLegDir(values:Array):void
		{
			var uid:String = String(values[0]);
			var robot:Robot = P2pWorld.robots[uid];
			
			var robRes:RobotResource = robot.resource as RobotResource;
			robRes.legMesh.rotationY = values[1];
		}
		
		public function fire(values:Array):void
		{
			var pid:String = String(values[0]);
			var type:uint = values[1];
			
			if(type==1)
			{
				var mainWep:WeaponMain = P2pWorld.mainWeapons[pid];
				var mainWepCon:MainWeaponController = mainWep.controller as MainWeaponController;
				mainWepCon.fire();
			}
		}
		
	}
}